﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using PersonalClient.Files;
using System.Windows.Interop;
using PersonalClient.Helper;

namespace PersonalClient
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //// 获取窗体句柄
            //IntPtr hwnd = new WindowInteropHelper(this).Handle;
            //// 获得窗体的 样式
            //long oldstyle = nativemethods.GetWindowLong(hwnd, nativemethods.gwl_style);
            //// 更改窗体的样式为无边框窗体
            //nativemethods.SetWindowLong(hwnd, nativemethods.gwl_style, oldstyle & ~nativemethods.ws_caption );
            //// setwindowlong(hwnd, gwl_exstyle, oldstyle & ~ws_ex_layered);
            //// 1 | 2 << 8 | 3 << 16  r=1,g=2,b=3 详见winuse.h文件
            //// 设置窗体为透明窗体
            ////nativemethods.SetLayeredWindowAttributes(hwnd, 1 | 2 << 8 | 3 << 16, 0, nativemethods.lwa_alpha);
            //// 创建圆角窗体  12 这个值可以根据自身项目进行设置
            //nativemethods.SetWindowRgn(hwnd, nativemethods.CreateRoundRectRgn(0, 0, Convert.ToInt32(this.ActualWidth), Convert.ToInt32(this.ActualHeight), 12, 12), true);

            map.Initial();
            acTxt.SelectOne += new Action<dynamic>(acTxt_SelectOne);
            map.LoadCompleted += (cname) => acTxt.CurrentCity = cname;
        }

        void acTxt_SelectOne(dynamic obj)
        {
            string lat = obj.location.lat;
            string lng = obj.location.lng;
            map.CenterAndZoom(lat, lng);
        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

    }
}
